using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the Ad class.
	/// </summary>
	[Serializable]
	public partial class AdCollection : ActiveList<Ad,AdCollection> 
	{	   
		public AdCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CSK_Store_Ad table.
	/// </summary>
	[Serializable]
	public partial class Ad : ActiveRecord<Ad>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Ad()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Ad(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public Ad(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Ad(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CSK_Store_Ad", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAdID = new TableSchema.TableColumn(schema);
				colvarAdID.ColumnName = "adID";
				colvarAdID.DataType = DbType.Int32;
				colvarAdID.MaxLength = 0;
				colvarAdID.AutoIncrement = true;
				colvarAdID.IsNullable = false;
				colvarAdID.IsPrimaryKey = true;
				colvarAdID.IsForeignKey = false;
				colvarAdID.IsReadOnly = false;
				colvarAdID.DefaultSetting = @"";
				colvarAdID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAdID);
				
				TableSchema.TableColumn colvarPageName = new TableSchema.TableColumn(schema);
				colvarPageName.ColumnName = "pageName";
				colvarPageName.DataType = DbType.String;
				colvarPageName.MaxLength = 50;
				colvarPageName.AutoIncrement = false;
				colvarPageName.IsNullable = true;
				colvarPageName.IsPrimaryKey = false;
				colvarPageName.IsForeignKey = false;
				colvarPageName.IsReadOnly = false;
				colvarPageName.DefaultSetting = @"";
				colvarPageName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPageName);
				
				TableSchema.TableColumn colvarListOrder = new TableSchema.TableColumn(schema);
				colvarListOrder.ColumnName = "listOrder";
				colvarListOrder.DataType = DbType.Int32;
				colvarListOrder.MaxLength = 0;
				colvarListOrder.AutoIncrement = false;
				colvarListOrder.IsNullable = false;
				colvarListOrder.IsPrimaryKey = false;
				colvarListOrder.IsForeignKey = false;
				colvarListOrder.IsReadOnly = false;
				
						colvarListOrder.DefaultSetting = @"((1))";
				colvarListOrder.ForeignKeyTableName = "";
				schema.Columns.Add(colvarListOrder);
				
				TableSchema.TableColumn colvarPlacement = new TableSchema.TableColumn(schema);
				colvarPlacement.ColumnName = "placement";
				colvarPlacement.DataType = DbType.String;
				colvarPlacement.MaxLength = 50;
				colvarPlacement.AutoIncrement = false;
				colvarPlacement.IsNullable = false;
				colvarPlacement.IsPrimaryKey = false;
				colvarPlacement.IsForeignKey = false;
				colvarPlacement.IsReadOnly = false;
				colvarPlacement.DefaultSetting = @"";
				colvarPlacement.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPlacement);
				
				TableSchema.TableColumn colvarAdText = new TableSchema.TableColumn(schema);
				colvarAdText.ColumnName = "adText";
				colvarAdText.DataType = DbType.String;
				colvarAdText.MaxLength = 2500;
				colvarAdText.AutoIncrement = false;
				colvarAdText.IsNullable = false;
				colvarAdText.IsPrimaryKey = false;
				colvarAdText.IsForeignKey = false;
				colvarAdText.IsReadOnly = false;
				colvarAdText.DefaultSetting = @"";
				colvarAdText.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAdText);
				
				TableSchema.TableColumn colvarProductSku = new TableSchema.TableColumn(schema);
				colvarProductSku.ColumnName = "productSku";
				colvarProductSku.DataType = DbType.String;
				colvarProductSku.MaxLength = 50;
				colvarProductSku.AutoIncrement = false;
				colvarProductSku.IsNullable = true;
				colvarProductSku.IsPrimaryKey = false;
				colvarProductSku.IsForeignKey = false;
				colvarProductSku.IsReadOnly = false;
				
						colvarProductSku.DefaultSetting = @"('')";
				colvarProductSku.ForeignKeyTableName = "";
				schema.Columns.Add(colvarProductSku);
				
				TableSchema.TableColumn colvarPromoID = new TableSchema.TableColumn(schema);
				colvarPromoID.ColumnName = "promoID";
				colvarPromoID.DataType = DbType.Int32;
				colvarPromoID.MaxLength = 0;
				colvarPromoID.AutoIncrement = false;
				colvarPromoID.IsNullable = true;
				colvarPromoID.IsPrimaryKey = false;
				colvarPromoID.IsForeignKey = false;
				colvarPromoID.IsReadOnly = false;
				
						colvarPromoID.DefaultSetting = @"((0))";
				colvarPromoID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPromoID);
				
				TableSchema.TableColumn colvarCategoryID = new TableSchema.TableColumn(schema);
				colvarCategoryID.ColumnName = "categoryID";
				colvarCategoryID.DataType = DbType.Int32;
				colvarCategoryID.MaxLength = 0;
				colvarCategoryID.AutoIncrement = false;
				colvarCategoryID.IsNullable = true;
				colvarCategoryID.IsPrimaryKey = false;
				colvarCategoryID.IsForeignKey = false;
				colvarCategoryID.IsReadOnly = false;
				
						colvarCategoryID.DefaultSetting = @"((0))";
				colvarCategoryID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryID);
				
				TableSchema.TableColumn colvarDateExpires = new TableSchema.TableColumn(schema);
				colvarDateExpires.ColumnName = "dateExpires";
				colvarDateExpires.DataType = DbType.DateTime;
				colvarDateExpires.MaxLength = 0;
				colvarDateExpires.AutoIncrement = false;
				colvarDateExpires.IsNullable = true;
				colvarDateExpires.IsPrimaryKey = false;
				colvarDateExpires.IsForeignKey = false;
				colvarDateExpires.IsReadOnly = false;
				colvarDateExpires.DefaultSetting = @"";
				colvarDateExpires.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateExpires);
				
				TableSchema.TableColumn colvarIsActive = new TableSchema.TableColumn(schema);
				colvarIsActive.ColumnName = "isActive";
				colvarIsActive.DataType = DbType.Boolean;
				colvarIsActive.MaxLength = 0;
				colvarIsActive.AutoIncrement = false;
				colvarIsActive.IsNullable = false;
				colvarIsActive.IsPrimaryKey = false;
				colvarIsActive.IsForeignKey = false;
				colvarIsActive.IsReadOnly = false;
				
						colvarIsActive.DefaultSetting = @"((1))";
				colvarIsActive.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsActive);
				
				TableSchema.TableColumn colvarIsDeleted = new TableSchema.TableColumn(schema);
				colvarIsDeleted.ColumnName = "isDeleted";
				colvarIsDeleted.DataType = DbType.Boolean;
				colvarIsDeleted.MaxLength = 0;
				colvarIsDeleted.AutoIncrement = false;
				colvarIsDeleted.IsNullable = false;
				colvarIsDeleted.IsPrimaryKey = false;
				colvarIsDeleted.IsForeignKey = false;
				colvarIsDeleted.IsReadOnly = false;
				
						colvarIsDeleted.DefaultSetting = @"((0))";
				colvarIsDeleted.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsDeleted);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "createdOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "createdBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "modifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "modifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CSK_Store_Ad",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AdID")]
		public int AdID 
		{
			get { return GetColumnValue<int>(Columns.AdID); }

			set { SetColumnValue(Columns.AdID, value); }

		}

		  
		[XmlAttribute("PageName")]
		public string PageName 
		{
			get { return GetColumnValue<string>(Columns.PageName); }

			set { SetColumnValue(Columns.PageName, value); }

		}

		  
		[XmlAttribute("ListOrder")]
		public int ListOrder 
		{
			get { return GetColumnValue<int>(Columns.ListOrder); }

			set { SetColumnValue(Columns.ListOrder, value); }

		}

		  
		[XmlAttribute("Placement")]
		public string Placement 
		{
			get { return GetColumnValue<string>(Columns.Placement); }

			set { SetColumnValue(Columns.Placement, value); }

		}

		  
		[XmlAttribute("AdText")]
		public string AdText 
		{
			get { return GetColumnValue<string>(Columns.AdText); }

			set { SetColumnValue(Columns.AdText, value); }

		}

		  
		[XmlAttribute("ProductSku")]
		public string ProductSku 
		{
			get { return GetColumnValue<string>(Columns.ProductSku); }

			set { SetColumnValue(Columns.ProductSku, value); }

		}

		
		
		//private int? propPromoID;
		[XmlAttribute("PromoID")]
		public int PromoID 
		{
			get
			{
			int? propPromoID = GetColumnValue<int?>(Columns.PromoID);
				if (!propPromoID.HasValue)
					return 0;
				return propPromoID.Value;
			}

		   set { SetColumnValue(Columns.PromoID, value); }

		}

		
		[XmlIgnore]
		public bool PromoIDHasValue
		{
			get { return GetColumnValue<int?>("promoID") != null; }

			set
			{
				int? propPromoID = GetColumnValue<int?>(Columns.PromoID);
				if (!value)
					SetColumnValue(Columns.PromoID, null);
				else if (value && !propPromoID.HasValue)
					SetColumnValue(Columns.PromoID, 0);
		   }

		}

		
		
		
		//private int? propCategoryID;
		[XmlAttribute("CategoryID")]
		public int CategoryID 
		{
			get
			{
			int? propCategoryID = GetColumnValue<int?>(Columns.CategoryID);
				if (!propCategoryID.HasValue)
					return 0;
				return propCategoryID.Value;
			}

		   set { SetColumnValue(Columns.CategoryID, value); }

		}

		
		[XmlIgnore]
		public bool CategoryIDHasValue
		{
			get { return GetColumnValue<int?>("categoryID") != null; }

			set
			{
				int? propCategoryID = GetColumnValue<int?>(Columns.CategoryID);
				if (!value)
					SetColumnValue(Columns.CategoryID, null);
				else if (value && !propCategoryID.HasValue)
					SetColumnValue(Columns.CategoryID, 0);
		   }

		}

		
		
		
		//private DateTime? propDateExpires;
		[XmlAttribute("DateExpires")]
		public DateTime DateExpires 
		{
			get
			{
			DateTime? propDateExpires = GetColumnValue<DateTime?>(Columns.DateExpires);
				if (!propDateExpires.HasValue)
					return new DateTime(1900,01, 01);
				return propDateExpires.Value;
			}

		   set { SetColumnValue(Columns.DateExpires, value); }

		}

		
		[XmlIgnore]
		public bool DateExpiresHasValue
		{
			get { return GetColumnValue<DateTime?>("dateExpires") != null; }

			set
			{
				DateTime? propDateExpires = GetColumnValue<DateTime?>(Columns.DateExpires);
				if (!value)
					SetColumnValue(Columns.DateExpires, null);
				else if (value && !propDateExpires.HasValue)
					SetColumnValue(Columns.DateExpires, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("IsActive")]
		public bool IsActive 
		{
			get { return GetColumnValue<bool>(Columns.IsActive); }

			set { SetColumnValue(Columns.IsActive, value); }

		}

		  
		[XmlAttribute("IsDeleted")]
		public bool IsDeleted 
		{
			get { return GetColumnValue<bool>(Columns.IsDeleted); }

			set { SetColumnValue(Columns.IsDeleted, value); }

		}

		
		
		//private DateTime? propCreatedOn;
		[XmlAttribute("CreatedOn")]
		public DateTime CreatedOn 
		{
			get
			{
			DateTime? propCreatedOn = GetColumnValue<DateTime?>(Columns.CreatedOn);
				if (!propCreatedOn.HasValue)
					return new DateTime(1900,01, 01);
				return propCreatedOn.Value;
			}

		   set { SetColumnValue(Columns.CreatedOn, value); }

		}

		
		[XmlIgnore]
		public bool CreatedOnHasValue
		{
			get { return GetColumnValue<DateTime?>("createdOn") != null; }

			set
			{
				DateTime? propCreatedOn = GetColumnValue<DateTime?>(Columns.CreatedOn);
				if (!value)
					SetColumnValue(Columns.CreatedOn, null);
				else if (value && !propCreatedOn.HasValue)
					SetColumnValue(Columns.CreatedOn, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }

			set { SetColumnValue(Columns.CreatedBy, value); }

		}

		
		
		//private DateTime? propModifiedOn;
		[XmlAttribute("ModifiedOn")]
		public DateTime ModifiedOn 
		{
			get
			{
			DateTime? propModifiedOn = GetColumnValue<DateTime?>(Columns.ModifiedOn);
				if (!propModifiedOn.HasValue)
					return new DateTime(1900,01, 01);
				return propModifiedOn.Value;
			}

		   set { SetColumnValue(Columns.ModifiedOn, value); }

		}

		
		[XmlIgnore]
		public bool ModifiedOnHasValue
		{
			get { return GetColumnValue<DateTime?>("modifiedOn") != null; }

			set
			{
				DateTime? propModifiedOn = GetColumnValue<DateTime?>(Columns.ModifiedOn);
				if (!value)
					SetColumnValue(Columns.ModifiedOn, null);
				else if (value && !propModifiedOn.HasValue)
					SetColumnValue(Columns.ModifiedOn, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>(Columns.ModifiedBy); }

			set { SetColumnValue(Columns.ModifiedBy, value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varPageName,int varListOrder,string varPlacement,string varAdText,string varProductSku,int varPromoID,int varCategoryID,DateTime varDateExpires,bool varIsActive,bool varIsDeleted,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy)
		{
			Ad item = new Ad();
			
			item.PageName = varPageName;
			
			item.ListOrder = varListOrder;
			
			item.Placement = varPlacement;
			
			item.AdText = varAdText;
			
			item.ProductSku = varProductSku;
			
			item.PromoID = varPromoID;
			
			item.CategoryID = varCategoryID;
			
			item.DateExpires = varDateExpires;
			
			item.IsActive = varIsActive;
			
			item.IsDeleted = varIsDeleted;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varAdID,string varPageName,int varListOrder,string varPlacement,string varAdText,string varProductSku,int varPromoID,int varCategoryID,DateTime varDateExpires,bool varIsActive,bool varIsDeleted,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy)
		{
			Ad item = new Ad();
			
				item.AdID = varAdID;
			
				item.PageName = varPageName;
			
				item.ListOrder = varListOrder;
			
				item.Placement = varPlacement;
			
				item.AdText = varAdText;
			
				item.ProductSku = varProductSku;
			
				item.PromoID = varPromoID;
			
				item.CategoryID = varCategoryID;
			
				item.DateExpires = varDateExpires;
			
				item.IsActive = varIsActive;
			
				item.IsDeleted = varIsDeleted;
			
				item.CreatedOn = varCreatedOn;
			
				item.CreatedBy = varCreatedBy;
			
				item.ModifiedOn = varModifiedOn;
			
				item.ModifiedBy = varModifiedBy;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn AdIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn PageNameColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn ListOrderColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn PlacementColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn AdTextColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn ProductSkuColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        public static TableSchema.TableColumn PromoIDColumn
        {
            get { return Schema.Columns[6]; }

        }

        
        
        
        public static TableSchema.TableColumn CategoryIDColumn
        {
            get { return Schema.Columns[7]; }

        }

        
        
        
        public static TableSchema.TableColumn DateExpiresColumn
        {
            get { return Schema.Columns[8]; }

        }

        
        
        
        public static TableSchema.TableColumn IsActiveColumn
        {
            get { return Schema.Columns[9]; }

        }

        
        
        
        public static TableSchema.TableColumn IsDeletedColumn
        {
            get { return Schema.Columns[10]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[11]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[12]; }

        }

        
        
        
        public static TableSchema.TableColumn ModifiedOnColumn
        {
            get { return Schema.Columns[13]; }

        }

        
        
        
        public static TableSchema.TableColumn ModifiedByColumn
        {
            get { return Schema.Columns[14]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AdID = @"adID";
			 public static string PageName = @"pageName";
			 public static string ListOrder = @"listOrder";
			 public static string Placement = @"placement";
			 public static string AdText = @"adText";
			 public static string ProductSku = @"productSku";
			 public static string PromoID = @"promoID";
			 public static string CategoryID = @"categoryID";
			 public static string DateExpires = @"dateExpires";
			 public static string IsActive = @"isActive";
			 public static string IsDeleted = @"isDeleted";
			 public static string CreatedOn = @"createdOn";
			 public static string CreatedBy = @"createdBy";
			 public static string ModifiedOn = @"modifiedOn";
			 public static string ModifiedBy = @"modifiedBy";
						
		}

		#endregion
		
		
		
	}

}

